package com.ioc.proxy;

import com.ioc.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 *
 */
@Component
public class UserDaoProxy implements UserDao {

    //目标对象
    @Autowired
    private UserDao userDao;

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    public void save() {
        before();
        //代理对象通过目标对象，调用目标对象的方法
        userDao.save();

        after();
    }

    public void before(){
        System.out.println("执行前:"+new Date().toLocaleString());
    }

    public void after(){
        System.out.println("执行后："+new Date().toString());
    }

}
